package com.webflux.servlet;

import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
 * Created by wangzhanjin on 2018/5/31.
 */
//@WebServlet("/SyncServlet")
public class SynServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        long t1 = System.currentTimeMillis();
        //执行业务代码,从req获取参数信息，把结果写回到rsp中
        doSomThing(req, resp);
        System.out.println("sync use:"+(System.currentTimeMillis()-t1));
    }

    private void doSomThing(HttpServletRequest req, HttpServletResponse resp)throws IOException {
        //模拟耗时操作
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        resp.getWriter().append("done");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
